from app.extensions import db
from datetime import datetime


class Question(db.Model):
    __tablename__ = 'questions'

    id = db.Column(db.Integer, primary_key=True, comment='题目编号')
    content_url = db.Column(db.String(255), nullable=False, comment='题目的存放地址')
    name = db.Column(db.String(32), unique=True, nullable=False, comment='垃圾名称')
    options = db.Column(db.JSON, nullable=False, comment='题目选项，如 {"A":0, "B":1, "C":2, "D":3}')
    answer = db.Column(db.String(1), nullable=False, comment='题目答案（A/B/C/D）')
    created_at = db.Column(db.DateTime, default=datetime.utcnow, comment='创建时间')

    def to_dict(self):
        return {
            'content_url': self.content_url,
            'options': self.options,
            'answer': self.answer
        }
